# 第一题
# a = [1,2,3,4,1,2,3,4,1,2,3,4]
# b = []
# for i in a:
#     if i not in b:
#         b.append(i)
# print(b)

# 第二题
# a = [1,32,45,324,12,56,87]
# b = len(a) - 1
# while b > 0:
#     b -= 1
#     for i in range(len(a) - 1):
#         if a[i] > a[i+1]:
#             a[i], a[i+1] = a[i+1], a[i]
#         else:
#             a[i], a[i+1] =a[i], a[i+1]
# print(a)


# if test == '2':
#     username = input('输入你的用户名')
#     if username == aaa.key:
#         password = input('请输入你的密码')
#     elif password == aaa.get('username'):
#         print('登陆成功')
#     else:
#         print('用户名或密码错误')


# 第三题
import json
f = open("data.json", 'r', encoding='UTF-8')
data = json.load(f)

print('请输入你的操作指令：0退出')
print('请输入你的操作指令：1注册')
print('请输入你的操作指令：2登录')
print('请输入你的操作指令：3修改密码')
print('请输入你的操作指令：4删除用户')
while True:
    test = input('输入你的指令：')
    if test == '1':
        username = input('请输入你的用户名：')
        if username in data:
            print('该用户已存在')
        elif len(username) < 0 or len(username) > 20:
            print('长度不合法')
        else:
            password = input('请输入密码')
            data[username] = password
            print('注册成功')

    elif test == '2':
        username = input('输入你的用户名')
        if username != data.keys:
            password = input('请输入你的密码')

            if password == data.get('username'):
                print('登陆成功')
            else:
                print('用户名或密码错误')
    elif test == '3':
        password = input('请输入你的密码')
        new_password = input('请输入你的新密码')
        if password != data.get('username') and password == new_password:
            print('密码输入错误或者两次密码输入一样')
        else:
            print('修改成功')
    elif test == '4':
        username = input('请输入你的用户名')
        password = input('请输入你的密码')
        if username == data.keys() and password == data.get('username'):
            data.pop('username')
            print('删除成功')
        else:
            print('用户名或密码错误')
    elif test == '0':
        break
    else:
        print('指令输入有误')
f = open("data.json", 'w', encoding='UTF-8')
json.dump(data, f, ensure_ascii=False)
f.close()


# 第四题
# w = input("请输入：")
# w2 = ""
# for i in w:
#     w2 = i+w2
# if w == w2:
# 	print("是回文！")
# else:
# 	print("不是回文！")














